package com.smartcar.driver.controller;

import com.alibaba.fastjson.JSONObject;
import com.smartcar.common.domain.User;
import com.smartcar.common.result.Result;
import com.smartcar.driver.common.domain.DriverFile;
import com.smartcar.driver.common.domain.request.DriverOrderVo;
import com.smartcar.driver.common.domain.request.FindFileVo;
import com.smartcar.driver.service.DriverService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("driver")
@Log4j2
public class DriverController {

    @Autowired
    private DriverService driverService;

    /**
     * 接单功能
     * */

    /**
     * 抢单功能
     */
    @PostMapping("scrambleForOrder")
    public Result scrambleForOrder(@RequestBody DriverOrderVo driverOrderVo) {
        log.info("方法名称：抢单，入参：{}", JSONObject.toJSONString(driverOrderVo));
        int i = driverService.scrambleForOrder(driverOrderVo);
        Result<Integer> result = new Result<>();
        if (i > 0) {
            result = Result.success(i);
        } else {
            result = Result.error("抢单失败");
        }
        log.info("方法名称：抢单，出参：{}", JSONObject.toJSONString(result));
        return result;
    }

    /**
     * 查询司机附件信息
     */
    @PostMapping("findDriverFileByUserNumber")
    public Result<DriverFile> selectDriverFile(@RequestBody FindFileVo findFileVo) {
        log.info("方法名称：查询司机附件信息,入参：{}", JSONObject.toJSONString(findFileVo));
        DriverFile driverFile = driverService.findDriverFileByUserNumber(findFileVo);
        Result<DriverFile> result = Result.success(driverFile);
        log.info("方法名称：查询司机附件信息,结果：{}", JSONObject.toJSONString(driverFile));
        return result;
    }

}
